﻿using Avalonia.Controls;
using FluentAvalonia.UI.Controls;
using iOSClub.App.Desktop.ToolPages;
using iOSClub.App.Desktop.ToolPages.Converter;
using iOSClub.App.Desktop.ToolPages.Encode;
using iOSClub.App.Desktop.ToolPages.Generate;
using iOSClub.App.Desktop.ViewModels.ToolPages;

namespace iOSClub.App.Desktop.Pages;

public partial class ToolPage : UserControl
{
    public ToolPage()
    {
        InitializeComponent();
        
        Navigate("Home");
    }
    
    private void ItemInvoked(object? sender, NavigationViewItemInvokedEventArgs e)
    {
        if (e.InvokedItemContainer.Tag is not string s) return;
        if (string.IsNullOrEmpty(s)) return;
        Navigate(s);
    }

    public void Navigate(object context)
    {
        if (context is Control control)
        {
            NavView.Content = control;
            return;
        }

        if (context is string str)
        {
            NavView.Content = str switch
            {
                "Home" => new ToolHomeView() { DataContext = new HomeViewModel() },
                "Converter" => new ConverterView() { DataContext = new ConverterViewModel() },
                "Translate" => new TranslateView(),
                "BaseConverter" => new BaseConverterView(),
                "RegexConverter" => new RegexConverterView(),
                "Encode" => new EncodeView() { DataContext = new EncodeViewModel() },
                "Base64Image" => new Base64ImageView(),
                "Base64String" => new Base64StringView(),
                "HtmlEncode" => new HtmlEncodeView(),
                "GZipEncode" => new GZipEncodeView(),
                "Generate" => new GenerateView() { DataContext = new GenerateViewModel() },
                "HashGenerate" => new HashGenerateView(),
                _ => new TextBlock() { Text = "当前还不支持" }
            };
            return;
        }

        NavView.Content =  new TextBlock() { Text = "当前还不支持" };
    }
}